﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NS_QuangCaoTiepThiBUS
{
    public class LoaiNoiDungBUS
    {
        public void Them(LoaiNoiDung lndDTO)
        {
            QCTTDataContext storeDB = new QCTTDataContext();

            storeDB.LoaiNoiDungs.InsertOnSubmit(lndDTO);

            storeDB.SubmitChanges();
        }

        public void Sua(LoaiNoiDung lndDTO)
        {
            QCTTDataContext storeDB = new QCTTDataContext();

            var query = storeDB.LoaiNoiDungs.Where(q => q.MaLoaiNoiDung == lndDTO.MaLoaiNoiDung).First();

            query.TenLoaiNoiDung = lndDTO.TenLoaiNoiDung;

            storeDB.SubmitChanges();
        }

        public void Xoa(LoaiNoiDung lndDTO)
        {
            QCTTDataContext storeDB = new QCTTDataContext();

            var query = storeDB.LoaiNoiDungs.Where(q => q.MaLoaiNoiDung == lndDTO.MaLoaiNoiDung).First();

            storeDB.LoaiNoiDungs.DeleteOnSubmit(query);

            storeDB.SubmitChanges();
        }

        public IList<LoaiNoiDung> LayDanhSachLoaiNoiDung()
        {
            QCTTDataContext storeDB = new QCTTDataContext();

            var query = storeDB.LoaiNoiDungs.ToList();

            return query;
        }

        public bool KiemTraTonTaiLoaiNoiDung(LoaiNoiDung lndDTO)
        {
            QCTTDataContext storeDB = new QCTTDataContext();

            var query = storeDB.LoaiNoiDungs.Where(q => q.MaLoaiNoiDung == lndDTO.MaLoaiNoiDung).ToList();

            if (query.Count > 0)
            {
                return true;
            }

            return false;
        }
    }
}
